import React, { useMemo } from 'react';
import { Tag,  } from 'antd';
import dayjs from 'dayjs';
import { useModel } from 'umi';
const dateFormat = 'YYYY-MM-DD';
import * as c from '@/services/consts';



export const DeployLogStatusTag: React.FC<{
  log: API.ServerInfoDeployLog | undefined;
  // action: string | undefined;
  // status: number | undefined;
  // statusDate: Date | undefined;
  }> = (props) => {

  const { log } = props;
  
  if(!log || !log?.action || !log?.begin) return <></>;

  const renderTag = useMemo(() => {
    let txtColor = '';

    let date = dayjs(log.begin);
    if(log.status == c.DeployLogStatus.Complated.value){
      let dateNow = dayjs(new Date());
      if (date.format(dateFormat) == dateNow.format(dateFormat)) {
        let hour = date.hour() + 4;
        if (hour > dateNow.hour()) {
          txtColor = 'success';
        } 
        else {
          txtColor = 'cyan';
        }
      }
    }
    else if(log.status == c.DeployLogStatus.Run.value){
      txtColor = 'blue';
    }  
    else {
      txtColor = 'error';
    }

    return (<>
      <Tag color={txtColor}>
      部署{c.getObjectText(c.DeployLogStatusOptions, log.status)} {date.format('HH:mm:ss')} {log.user}
      </Tag>
    </>);
  }, [log]);

  return <>{renderTag}</>;
};

